const express = require("express");
const comm = require('../../../../dbcomm');
const route_xzt = express.Router();

route_xzt.get('/show',function(req,res){
    comm.exec("select * from xzt",function (err,result){
        if(err) throw err;
        var json = {
            code:0
            ,msg:'成功'
            ,data:result
        };
        res.send(json); // send end({aa:123})....
    });
   
});

route_xzt.post('/addXzt',function(req,res){
    
    // console.log(req.body);
    
    var a = req.body;
    
    var ti = a.ti;
    var ming = a.ming;

    var obj1 = JSON.parse(ti) ;
    var obj2 = JSON.parse(ming) ;
    var length = obj1.length;
    // console.log(obj1);
    // console.log(obj2);
    // console.log(obj1.length);

    // console.log(obj1[0]);

    // var length = ti.length;
    // console.log(length);
    // console.log(arr.length);

    for(var i=0; i<length; i++){
        // console.log(a.ming[i]);
        var quid = obj1[i];
        var quanswer = obj2[i];
        // console.log(quid);
        // console.log(quanswer);
        comm.exec("insert into xzt(quid, quanswer) values(?, ?)",[quid, quanswer],function (err,result){
            if(err) throw err;
            // res.send(result); // send end({aa:123})....
        });
    }

    // comm.exec("insert into xzt(quid, quanswer) values(?, ?)",[a.ming, a.ming],function (err,result){
    //     if(err) throw err;
    //     res.send(result); // send end({aa:123})....
    // });
   
});



module.exports = route_xzt;